package com.cy.dao;

import com.cy.pojo.Student;
import com.cy.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created with IDEA2020.3.3 JDK1.8 Mysql 5.7 maven3.6.3
 *
 * @Auther: 张鹏宇
 * @Date: 2021/04/12/16:29
 * @Description:
 */
public class StudentDaoImpl implements StudentDao {

    @Override
    public List<Student> selectStudents() {
//        获取SqlSession对象
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        String sqlId = "com.cy.dao.StudentDao.selectStudents";
        List<Student> students = sqlSession.selectList(sqlId);

        students.forEach(System.out :: println);
//        selectList.forEach(System.out :: println);

//关闭
        sqlSession.close();
        return students;
    }

    @Override
    public int insterStudent(Student student) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        String splId = "com.cy.dao.StudentDao.insterStudent";
        int insert = sqlSession.insert(splId, student);
        sqlSession.commit();



        return insert;
    }
}
